/*
 Copyright 2007 Ole Rogeberg

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package org.lifeyears.web.action;

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;


/**
 * Starts Jetty for for lifeyears-web
 **/
public class StartJetty
{
    //the port to listen to
    private static final int PORT = 8080;

    public static void main( final String[] args )
        throws Exception
    {
        final Connector connector = new SelectChannelConnector();
        connector.setPort( PORT );

        final WebAppContext siteContext = new WebAppContext( "src/main/webapp", "/" );

        final Server server = new Server( 0 );
        server.addHandler( siteContext );
        server.addConnector( connector );

        final long startTime = System.currentTimeMillis();
        System.out.println( "Starting server..." );

        server.start();

        final double totalTime = ( System.currentTimeMillis() - startTime) / 1000.0;
        System.out.println( "Start-up time: " + totalTime + "s. \n" + "Started Jetty on http://localhost:" + PORT + "/" );

    }
}
